package com.cn.web.controller.EM.UserInfo;

import com.alibaba.fastjson2.JSONObject;
import com.cn.bean.vo.EM.UserInfo.UserDepartmentsBean;
import com.cn.bean.vo.EM.partRegt.PageInfo;
import com.cn.common.utils.JsonConverter;
import com.cn.service.server.EM.UserInfo.UserDepartmentsService;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@Transactional
@RequestMapping("/UserDe")
public class UserDepartmentsController {
    private final UserDepartmentsService userDepartmentsService;

    @Autowired(required = false)
    public UserDepartmentsController(UserDepartmentsService userDepartmentsService) {
        this.userDepartmentsService = userDepartmentsService;
    }

    @RequestMapping("/getUserDe")
    @ResponseBody
    public List<UserDepartmentsBean> getUserDe(@RequestBody JSONObject jsonObject) throws JsonProcessingException {
        UserDepartmentsBean userDepartments = new UserDepartmentsBean();
        PageInfo pageInfo = new PageInfo();
        String limit = jsonObject.getString("limit");
        String page = jsonObject.getString("page");
        String userCode = jsonObject.getString("input1");
        String userName = jsonObject.getString("input2");
        String deptCode = jsonObject.getString("input3");
        String deptName = jsonObject.getString("input4");
        String userCodeSingle = jsonObject.getString("input5");
        pageInfo.setPage(page);
        pageInfo.setLimit(limit);
        userDepartments.setUserCode(userCode);
        userDepartments.setUserName(userName);
        userDepartments.setDeptCode(deptCode);
        userDepartments.setDeptName(deptName);
        userDepartments.setUserCodeSingle(userCodeSingle);
        String jsonString = JsonConverter.convertToCustomJson(userDepartments, null, pageInfo);

        return userDepartmentsService.getUserDe(jsonString);

    }

}
